package it.unipd.dei.bd.icineasti.database;

import it.unipd.dei.bd.icineasti.resource.Sala;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.List;
import java.sql.ResultSet;

/**
 * Fa un update dei dati di una sala a partire da un'istanza di Sala.
 * 
 * @author Bardelle Renzo
 * @version 1.00
 */

public class UpdateSalaDatabase {

	private static final String STATEMENT = 	"UPDATE sala SET " +
												"sigla=?," +
												"nome=?," +
												"totaleposti=?" +
												"WHERE idsala=?";

	private final Connection con;
	private final Sala sala;
	
	public UpdateSalaDatabase(Connection con, Sala sala) {
		this.con = con;
		this.sala = sala;
	}

	public void updateSala() throws SQLException {

		PreparedStatement pstmt = null;
		
		try {
			
			pstmt = con.prepareStatement(STATEMENT);
			
			pstmt.setString(1, sala.getSigla());
			pstmt.setString(2, sala.getNome());
			pstmt.setInt(3, sala.getTotalePosti());
			pstmt.setInt(4, sala.getIdSala());
			
			pstmt.execute();
			
		} finally {
			if (pstmt != null) {
				pstmt.close();
			}
			
			con.close();
		}
	}
}